<template>
    利息:
    <select v-model="I_Id">
        <option value="0">请选择</option>
        <option v-for="item in K" :key="item.I_Id" :value="item.I_Id">{{ item.I_Inserest }}</option>
    </select>
    <input type="button" value="查找" @click="Show">

    <table>
        <thead>
            <tr>
                <td>编号</td>
                <td>借款项目名称</td>
                <td>借款金额</td>
                <td>最高借款日期</td>
                <td>人数</td>
                <td>利率</td>

                <td>操作</td>
            </tr>
        </thead>
        <tbody>
            <tr v-for="item in data" :key="item.BId">
                <td>{{ item.BId }}</td>
                <td>{{ item.B_Name }}</td>
                <td>{{ item.B_All }}</td>
                <td>{{ item.B_Year }}</td>
                <td>{{ item.B_Num }}</td>
                <td>{{ item.I_Inserest }}</td>
                <td><input type="button" value="我要借款" @click="Borrow(item.BId)"></td>
            </tr>
        </tbody>
    </table>
    <span>
        总页数：{{ Page.TotalCount }}总页数{{ Page.PageCount }}当前页数{{ Page.PageIndex }}/{{ Page.PageCount }}
        <a href="#" @click="PageShow('f')">首页</a>
        <a href="#" @click="PageShow('n')">上一页</a>
        <a href="#" @click="PageShow('u')">下一页</a>
        <a href="#" @click="PageShow('e')">尾页</a>

        <select v-model="Shows" @click="Showss">
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>

        </select>

        <input type="text" v-model="Jump">
        <input type="button" value="跳转" @click="Jumpss">

    </span>
</template>
<script lang="ts" setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { onMounted } from 'vue';
import axios from 'axios';
const data = ref([{
    BId: '',
    B_Name: '',
    B_All: '',
    B_Year: '',
    B_Num: '',
    I_Inserest: '',
}])
onMounted(() => {
    Bind()
    Show()

})
const I_Id = ref(0);
const K = ref([]);
//下拉框
const Bind = () => {
    axios.get('http://localhost:25190/api/Demo/Bind')
        .then(res => {
            K.value = res.data;
        })

}
const Page = ({
    PageIndex: 1,
    PageSize: 1,
    TotalCount: 0,
    PageCount: 0,
});
//显示
const Show = () => {
    axios.get('http://localhost:25190/api/Demo/Show', {
        params: {
            I_Id: I_Id.value,
            PageIndex: Page.PageIndex,
            PageSize: Page.PageSize,
        }
    })
        .then(res => {

            console.log(res.data);
            data.value = res.data.list;
            Page.TotalCount = res.data.TotalCount;
            Page.PageCount = res.data.PageCount;
        })
        .catch(error => {
            console.log(error);
        })
}
const router = useRouter();
const Borrow = (BId: number) => {
    alert(BId)
    router.push({
        name: 'Borrow',
        params: {
            BId: BId
        }
    })

}

const PageShow = (msg: string) => {
    switch (msg) {
        case 'f': {
            Page.PageIndex = 1;
            Show();
            break;
        }
        case 'n': {
            if ((Page.PageIndex - 1) < 1) {
                alert("不能小于1")
                Page.PageIndex = 1;
                return;
            }
            Page.PageIndex = Page.PageIndex - 1;
            break;

        }
        case 'u': {
            if ((Page.PageIndex + 1) > Page.PageCount) {
                alert("不能大于总页数")
                Page.PageIndex = Page.PageCount;
                return;
            }

            Page.PageIndex = Page.PageIndex + 1;
            break;
        }
        case 'e': {
            Page.PageIndex = Page.PageCount;
            break;
        }
    }
    Show();
}
const Shows = ref(1);
const Showss = () => {
    Page.PageSize = Shows.value;
    Show();
}
const Jump = ref();
const Jumpss = () => {
    if (Page.PageIndex < 1) {
        alert("不能小于1")
        Page.PageIndex = 1;
        return;
    }
    Page.PageIndex = Jump.value;
    Show();
}
</script>